package org.gm.listener;

import lombok.AllArgsConstructor;
import org.gm.config.SchedulerConfig;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;

@Component
@AllArgsConstructor
public class SpringEventListener implements ApplicationListener<ApplicationEvent> {
    private ExecutorService executorService;

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if(event instanceof ContextClosedEvent) {
            closeEvent((ContextClosedEvent) event);
        }
    }

    private void closeEvent(ContextClosedEvent event) {
        executorService.shutdown();
    }
}
